package com.infoauto.opc.gateway.messages.util;

import com.infoauto.opc.gateway.messages.util.serialize.ISerializer;
import com.infoauto.opc.gateway.messages.util.serialize.support.JSONSerializer;


public class SerializeUtils {

    private static ISerializer iSerializer = (ISerializer) JSONSerializer.getDefaultInstance();

    //序列化
    public static byte[] serialize(Object obj) {
        if (obj instanceof byte[]) {
            return (byte[]) obj;
        } else {
            return iSerializer.serialize(obj);
        }
    }

    //反序列化
    public static <T> T deserialize(byte[] data, Class<T> tpl) {
        if (tpl == byte[].class) {
            return (T) data;
        } else {
            return iSerializer.deserialize(data, tpl);
        }
    }
}
